<template>
  <zm-panel :visible.sync="value" @change="close" class="panelContainer">
    <div slot="title">
        <div class="dib">{{ obj.customerName }}</div>
        <tag-type
          :value="invoiceDesc.value"
          :msg="invoiceDesc.label"
        />
      </div>
    <!-- <app-block>
      <zm-button @click="onRecovery" t="submit" custtxt="回收" v-if="obj.isRecycle==='1'"></zm-button>
      <zm-button @click="onEdit" t="submit" custtxt="编辑" v-if="obj.isRecycle==='1'"></zm-button>
      <zm-button @click="ondel" t="submit" custtxt="删除"></zm-button>
    </app-block> -->
    <app-block>
      <component :ref="tabType" :is="tabType" :obj="obj"></component>
    </app-block>
    <edit-invoice
        v-if="editParams.visible"
        v-model="editParams.visible"
        :obj="editParams.obj"
        @after="getInfo"
      ></edit-invoice>
    <div slot="footer" class="tr"></div>
  </zm-panel>
</template>

<script>
import panelMixin from '@/mixins/panelMixin'
import { invoiceType } from './const'
import dataInfo from './dataInfo'
import EditInvoice from '../New'
import {recycleInvoice} from '@/api/src/invoice'
import api from '@/api'
import TagType from '@/components/TagType'

export default {
  components: { dataInfo, EditInvoice, TagType },
  mixins: [panelMixin],
  data () {
    return {
      invoiceType,

      tabType: 'dataInfo',
      form: {
      },
      editParams: {
        visible: false,
        obj: {}
      }
    }
  },
  computed: {
    invoiceDesc () {
      return this.invoiceType.find(item => {
        return item.value === this.obj.isRecycle
      })
    }
  },
  created () {

  },
  methods: {
    getInfo () {
      this.$refs[this.form.tabType].getInfo()
    },
    onRecovery () {
      this.$prompt('确定回收此发票，回收后此发票记录将作废，请慎重操作！', '回收', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPlaceholder: '请输入备注信息 , 必填项',
        inputType: 'textarea',
        inputPattern: /\S/,
        inputErrorMessage: '请输入备注'
      }).then(async () => {
        await recycleInvoice({id: this.obj.id, isRecycle: '2'})
        this.$message.success('回收成功')
        this.$emit('after')
        this.close()
      }).catch(() => {

      })
    },
    onEdit () {
      this.editParams = {
        visible: true,
        obj: this.obj
      }
    },
    ondel () {
      const text = '确定删除已开票记录，关联的销售单发票记录也会被删除，请慎重操作！'
      this.$confirm(text, '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          await api.invoice.delete({ id: this.obj.id })
          this.$message.success('删除成功')
          this.$emit('after')
          this.close()
        })
        .catch(() => {})
    }
  }
}
</script>

<style scoped lang="stylus"></style>
